package pkg

import (
	"aftersale/config"
	"aftersale/global/model"
	"fmt"
	"time"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

func MysqlConn() {
	var err error
	model.DB, err = gorm.Open(mysql.Open(fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=True&loc=Local", config.Conf.Mysql.User, config.Conf.Mysql.Password, config.Conf.Mysql.Addr, config.Conf.Mysql.Database)))
	if err != nil {
		panic(err)
	}
	db, err := model.DB.DB()
	if err != nil {
		panic(err)
	}
	db.SetMaxIdleConns(10)
	db.SetMaxOpenConns(100)
	db.SetConnMaxLifetime(time.Hour)
	fmt.Println("mysql connect success")
}
